/**
 * 
 */
package com.newtribe.net;

import java.nio.Buffer;
import java.nio.ByteBuffer;

/**
 * @author newtribe
 *
 */
public class DataPacket {

	
	private ByteBuffer bb = null;
    private int size = 0;
    
    public DataPacket(int capacity) {
    	bb = ByteBuffer.allocateDirect(capacity);
    	size = capacity;

    }
    public DataPacket wrap(byte[] buffer) {
    	
    	this.bb =ByteBuffer.wrap(buffer) ;
    	this.size =buffer.length;
   
    	return this ;
    }
    
    
    public  byte get() {
    	return bb.get();
    }

    public  DataPacket put(byte b) {
    	bb.put(b) ;
    	return this ;
    }
    
    public  DataPacket putInt(int value) {
    	
    	bb.putInt(value) ;
    	return this ;
    	
	}
    
    
    public void get(byte[] dst) {

    	bb.get(dst) ;
    }

    
    public  void put(byte[] src) {
    	bb.put(src, 0, src.length);
    }
    
    public int capacity(){
        return bb.capacity();
    }
    public void flip() {
    	bb.flip();
    }
    
    public final int position() {
    	return bb.position();
    }
    
    public final void position(int newPosition) {
    	bb.position(newPosition);
    }
    
    public final byte[] array() {
    	return bb.array();
    }
 	// return size in bytes
 	public int size() {
         return size;
 	//return bb.capacity(); //this.end - this.start;
 	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
